﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Maticsoft.Common;

namespace Maticsoft.Web
{
    public partial class UserAddrList : PageBaseMember
    {
        protected void Page_Load( object sender, EventArgs e )
        {
            Check();
            UserLeft1.FlagId = "5";

            if (Request.QueryString["op"] == "del")
            {
                DeleteItem();
            }

            if (!IsPostBack)
            {
                BindList();
            }
        }

        protected void DeleteItem( )
        {
            BLL.DeliveryAddr delBLL = new BLL.DeliveryAddr();
            Model.DeliveryAddr delModel = delBLL.GetModel(int.Parse(Request.QueryString["id"]));
            if (delModel != null && delModel.UserId.ToString() == this.UserId)
            {
                delModel.IsActive = 0;
                delModel.UpdateTime = DateTime.Now;
                delBLL.Update(delModel);
            }
        }

        protected void BindList( )
        {
            BLL.DeliveryAddr delBLL = new BLL.DeliveryAddr();
            string strWhere = "IsActive=1 and UserId=" + this.UserId;
            string strOrderBy = "DeliveryId desc";
            int count = delBLL.GetRecordCount(strWhere);
            AspNetPager1.RecordCount = count;
            DataSet ds = delBLL.GetListByPage(strWhere, strOrderBy, AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }

        protected string GetLocation(object locationId)
        {
            int locId = DigitHelper.GetInt32(locationId);
            BLL.LocationInfo locBLL = new BLL.LocationInfo();
            Model.LocationInfo locModel = locBLL.GetModel(locId);
            if (locModel != null)
            {
                return locModel.pName + " " + locModel.cName;
            }

            return "";
        }

        protected void AspNetPager1_PageChanging( object src, Wuqi.Webdiyer.PageChangingEventArgs e )
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            BindList();
        }
    }
}